home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: macro that return value, how?
- Date: 01 Mar 1996 00:17:49 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb29171749@qcd.lanl.gov>
- References: <3133e87b.868433@news.csus.edu>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: wleong@sfsu.edu's message of Wed, 28 Feb 1996 05:35:35 GMT
-
- In article <3133e87b.868433@news.csus.edu>
- wleong@sfsu.edu (Jerry Leong) writes:
-
- JL:
- JL: Hi,
- JL: I need to define a macro that will first calculate a given a
- JL: parameter and then return it. How can I do that?
- JL:
- JL: p/s: Say I pass a value to the macro, macro will perform some
- JL: addition, then return the value.
- JL:
- JL: #define add1(x) { x+=VAR; return x; }
- JL:
- JL: something like that by the above does not compile.
- JL: Thanx in advance!
-
- I think, but am not sure, that you have misunderstood the concept of
- macros. Macros never calculate anything, they replace the pp-tokens
- that you type in (e.g. add1 followed by ( followed by x followed by ))
- by another set of pp-tokens that it generates (e.g. the pp-tokens: {
- x += VAR ; return x ; }) before the stream is analyzed for the meaning of
- the program. If you could have written { x+=VAR; return x; } in some
- place, you can also write add1(x) at the same point (with the above
- definition).
-
- In other words, macros are substitution rules, not calculators.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-